var loadDataUrl = '/ajax/more.html'; // 获取更多数据URL

var $document = $(document);
var docHeight = document.documentElement.offsetHeight;
var winHeight = window.screen.height;

var getItem = function(data){
    return '<li>'+
        '<img class="fl" src="'+ data.img +'">'+
        '<div class="info fl">'+
            '<h2>'+ data.title +'</h2>'+
            '<div class="process"><span style="width:'+ data.process +'"></span></div>'+
            '<div class="times"><span class="fl">总需'+ data.total +'</span><span class="fr">剩余<em>'+ data.needs +'</em></span></div>'+
        '</div>'+
        '<a href="/url/?id='+ data.id +'" class="btn fr">立即夺宝</a>'+
    '</li>';
};

var loadMore = function(){
    loadMore.loading = 1;
    $('.loading-holder').show();
    $.get(loadDataUrl, function(data){
        if(data.retcode == 0){
            // 成功取到数据
            // data:{retcode:0,retdesc:"拉取数据成功",result:[{img:'url.jpg',title:'','process':'35%',id: 123, total: 1688, needs: 126}]}
            var htm = '';
            $.each(data.result,function(){
                htm += getItem(this);
            });
            $('.good').append(htm);
        }else{
            console.log(data.retdesc);
        }
        $('.loading-holder').hide();
        loadMore.loading = 0;
    });
};

$('.goods').dropload({
    scrollArea: window,
    loadUpFn: function(me){
        location.reload();
    },
    domUp: {
        domRefresh: '<div class="dropload-refresh">下拉刷新</div>',
        domUpdate : '<div class="dropload-update">释放更新</div>'
    }
});


$document.on('scroll',function(){
    docHeight - winHeight - document.body.scrollTop < 150 && !loadMore.loading && loadMore();
});